# 连接数据库
import mysql.connector
from flask import Flask, jsonify

app = Flask(__name__)

# 连接数据库
mydb = mysql.connector.connect(
    host="localhost",
    user="your_username",
    password="your_password",
    database="your_database"
)

@app.route('/students/<student_id>', methods=['GET'])
def get_student(student_id):
    mycursor = mydb.cursor()
    sql = "SELECT * FROM students WHERE student_id = %s"
    val = (student_id,)
    mycursor.execute(sql, val)
    student = mycursor.fetchone()
    if student:
        student_info = {
            "student_id": student[0],
            "name": student[1],
            "gender": student[2],
            "class": student[3]
        }
        return jsonify(student_info)
    else:
        return jsonify({"message": "Student not found"})

if __name__ == '__main__':
    app.run(debug=True)
